﻿using Resonance.TrainNode.Contracts.Services;
using Resonance.TrainNode.Contracts.Entities;
using System.Collections.Generic;
using System.Linq;

namespace Resonance.TrainNode.Services
{
	public class TrainNodeService : ITrainNodeService
	{
		public void AddPatternsToSession(string sessionID, TrainPattern[] patterns)
		{
			SessionManager.AddPatterns(sessionID, patterns);
		}

		public void CreateNNet(string sessionID, ActivationFunctionEnum activationFunction, double sigmoidAlpha, string NNetID, int inputNeuronsCount, int[] layersNeuronsCount)
		{
			SessionManager.CreateNNet(sessionID, activationFunction, sigmoidAlpha, NNetID, inputNeuronsCount, layersNeuronsCount);
		}

		public void AddSession(string sessionID, string description)
		{
			SessionManager.AddSession(sessionID, description);
		}

		public void AddNNetToSession(string sessionID, NNet net)
		{
			SessionManager.AddNNet(sessionID, net);
		}

		public void AddJobToSession(string sessionID, string jobID, string NNetID, TrainAlgorithmTypeEnum trainAlgorithm, TrainParameters trainParams)
		{
			SessionManager.AddJob(sessionID, jobID, NNetID, trainAlgorithm, trainParams);
		}

		public NNet GetJobTrainResult(string sessionID, string jobID)
		{
			return SessionManager.GetJobResult(sessionID, jobID);
		}

		public Contracts.Entities.NodeInfo GetNodeInfo()
		{
			return GlobalTrain.Node;
		}

		public TrainSession[] GetSessions()
		{
			return SessionManager.GetSessionList().ToArray();
		}

		public TrainSession GetSessionByID(string sessionID)
		{
			return SessionManager.GetSessionByID(sessionID);
		}

		public TrainJob[] GetSessionJobs(string sessionID)
		{
			return SessionManager.GetSessionJobs(sessionID).ToArray();
		}

		public void RemoveJobFromSession(string sessionID, string jobID)
		{
			SessionManager.RemoveJob(sessionID, jobID);
		}

		public void RemoveSession(string sessionID)
		{
			SessionManager.RemoveSession(sessionID);
		}

		public void RemoveNNetFromSession(string sessionID, string NNetID)
		{
			SessionManager.RemoveNNet(sessionID, NNetID);
		}

		public void SetNodeInfo(string nodeDescription, string nodeUniqueName)
		{
			NodeInfo ni = GlobalTrain.Node;
			ni.Description = nodeDescription;
			ni.UniqueName = nodeUniqueName;
			GlobalTrain.Node = ni;
		}

		public void StartTrainSession(string sessionID)
		{
			SessionManager.StartSession(sessionID);
		}

		public void StopTrainSession(string sessionID)
		{
			SessionManager.StopSession(sessionID);
		}

	}
}
